package com.zr.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zr.common.annotation.Log;
import com.zr.common.core.controller.BaseController;
import com.zr.common.core.domain.AjaxResult;
import com.zr.common.enums.BusinessType;
import com.zr.system.domain.SysAnnounce;
import com.zr.system.service.ISysAnnounceService;
import com.zr.common.utils.poi.ExcelUtil;
import com.zr.common.core.page.TableDataInfo;

/**
 * 移动端通告Controller
 * 
 * @author why
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/system/announce")
public class SysAnnounceController extends BaseController
{
    @Autowired
    private ISysAnnounceService sysAnnounceService;

    /**
     * 查询移动端通告列表
     */
    @PreAuthorize("@ss.hasPermi('system:announce:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAnnounce sysAnnounce)
    {
        startPage();
        List<SysAnnounce> list = sysAnnounceService.selectSysAnnounceList(sysAnnounce);
        return getDataTable(list);
    }

    /**
     * 导出移动端通告列表
     */
    @PreAuthorize("@ss.hasPermi('system:announce:export')")
    @Log(title = "移动端通告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAnnounce sysAnnounce)
    {
        List<SysAnnounce> list = sysAnnounceService.selectSysAnnounceList(sysAnnounce);
        ExcelUtil<SysAnnounce> util = new ExcelUtil<SysAnnounce>(SysAnnounce.class);
        util.exportExcel(response, list, "移动端通告数据");
    }

    /**
     * 获取移动端通告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:announce:query')")
    @GetMapping(value = "/{announceId}")
    public AjaxResult getInfo(@PathVariable("announceId") Long announceId)
    {
        return AjaxResult.success(sysAnnounceService.selectSysAnnounceByAnnounceId(announceId));
    }

    /**
     * 新增移动端通告
     */
    @PreAuthorize("@ss.hasPermi('system:announce:add')")
    @Log(title = "移动端通告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAnnounce sysAnnounce)
    {
        return toAjax(sysAnnounceService.insertSysAnnounce(sysAnnounce));
    }

    /**
     * 修改移动端通告
     */
    @PreAuthorize("@ss.hasPermi('system:announce:edit')")
    @Log(title = "移动端通告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAnnounce sysAnnounce)
    {
        return toAjax(sysAnnounceService.updateSysAnnounce(sysAnnounce));
    }

    /**
     * 删除移动端通告
     */
    @PreAuthorize("@ss.hasPermi('system:announce:remove')")
    @Log(title = "移动端通告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{announceIds}")
    public AjaxResult remove(@PathVariable Long[] announceIds)
    {
        return toAjax(sysAnnounceService.deleteSysAnnounceByAnnounceIds(announceIds));
    }

    /**
     * 获取最新详细公告
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/latest/")
    public AjaxResult getLatestInfo(Long roleId)
    {
        return AjaxResult.success(sysAnnounceService.selectLatestAnnounce(roleId));
    }
}
